package com.example.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.example.dao.YearRepository;
import com.example.entity.GuanXi_YM;
import com.example.entity.Month;
import com.example.entity.Year;
import com.example.service.YearService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 *
 */
@Service
public class YearServiceImpl implements YearService {
    @Autowired
    YearRepository yearRepository;

    @Override
    public Year insert(Year y) {
        String yearStr = y.getYear();
        Year year_temp = yearRepository.findByYear(yearStr);
        if (year_temp == null) {
            String uuid = UUID.randomUUID().toString();
            y.setLogicId(uuid);
            Year year = yearRepository.save(y);
            return year;
        }
        Optional<Year> year_Optional = yearRepository.findById(year_temp.getId());
        Year year = year_Optional.get();
        return year;
    }


}
